<template>
  <div class="remarkReview">
    <!-- 搜索 -->
    <div class="section">
      <h3>备注审核</h3>
    </div>
    <el-table
      :height="tabHeight"
      border
      style="width: 99%"
      @selection-change="selectTable"
      align="center"
      :data="tableData"
    >
      <el-table-column type="selection" width="35"></el-table-column>
      <el-table-column prop="id" label="ID" width="60"></el-table-column>
      <el-table-column prop="company_name" label="所属CP"></el-table-column>
      <el-table-column prop="username" label="用户名"></el-table-column>
      <el-table-column label="申请活动" width="220">
        <template slot-scope="scope">
          <span>{{ scope.row.activity_name }}</span>
          <el-button
            type="text"
            size="mini"
            @click="showRemarkdetail(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        prop="audit_time"
        label="审核时间"
        width="160"
      ></el-table-column>
      <el-table-column
        prop="audit_type"
        label="备注类型"
        width="90"
      ></el-table-column>
      <el-table-column prop="audit_remark" label="备注"></el-table-column>
      <el-table-column label="修改备注" width="60">
        <template slot-scope="scope">
          <el-button
            type="primary"
            plain
            size="mini"
            @click="changeRemark(scope.row)"
            icon="el-icon-edit"
            circle
          ></el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button
            type="success"
            class="operateButton"
            plain
            size="mini"
            @click="passSuccess(scope.row)"
            >通过</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="bottom">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="pagenationData.currentPage"
        :page-size="pagenationData.pageSize"
        :total="pagenationData.pageTotal"
        background
        layout="prev, pager, next"
        prev-text="上一页"
        next-text="下一页"
      ></el-pagination>
      <el-button type="primary" @click="passThrough">一键通过</el-button>
    </div>
    <!-- 修改备注 -->
    <ChangeRemark
      v-if="changeRemarkdialog.show"
      :isShow="changeRemarkdialog.show"
      :dialogRow="changeRemarkdialog.dialogRow"
      @closeDialog="hideChangeRemarkdialog"
    ></ChangeRemark>
    <!-- 查看详情 -->
    <EventDetail
      v-if="eventDetaildialog.show"
      :isShow="eventDetaildialog.show"
      :dialogRow="eventDetaildialog.dialogRow"
      @closeDialog="hideEventDetaildialog"
    ></EventDetail>
  </div>
</template>
<script>
import {
  getRemarkList,
  passRemark,
  activityDetail,
  onePassRemark,
} from "@/api/eventManage";
import ChangeRemark from "./component/remarkReview/changeRemark";
import EventDetail from "./component/eventList/eventDetail";

export default {
  name: "remarkReview",
  inject: ["reload"],
  data() {
    return {
      tabHeight: window.innerHeight - 230,
      search: {},
      tableData: [],
      loading: false,
      multipleSelection: [], //复选框选中
      pagenationData: {
        pageTotal: 0,
        currentPage: 1,
        pageSize: 20,
      },
      pageData: {
        page: 1,
        limit: 20,
      },
      applyDetaildialog: {
        show: false,
        dialogRow: [],
      },
      changeRemarkdialog: {
        show: false,
        dialogRow: {},
      },
      eventDetaildialog: {
        show: false,
        dialogRow: {},
      },
    };
  },
  components: {
    ChangeRemark,
    EventDetail,
  },
  mounted() {
    this.getRemarkList();
  },
  methods: {
    // 获取数据列表
    getRemarkList() {
      const para = Object.assign({}, this.pageData);
      getRemarkList(para).then((res) => {
        if (res.data == null) {
          this.tableData = [];
          this.pagenationData.pageTotal = 0;
        } else {
          this.tableData = res.data;
          // this.pagenationData.pageTotal = res.data.count;
        }
        this.loading = false;
      });
    },
    // 上下分页
    handleCurrentChange(val) {
      this.pageData.page = val;
      this.search.page = val;
      this.getRemarkList();
    },
    // 当用户手动勾选数据行的 Checkbox 时触发的事件
    selectTable(val, row) {
      this.multipleSelection = val;
    },
    // 查看活动详情
    showRemarkdetail(row) {
      const para = Object.assign({}, { activity_id: row.activity_id });
      activityDetail(para).then((res) => {
        if (res.data == null) {
          this.eventDetaildialog.dialogRow = [];
        } else {
          this.eventDetaildialog.dialogRow = res.data;
        }
        this.eventDetaildialog.show = true;
      });
    },
    hideEventDetaildialog() {
      this.eventDetaildialog.show = false;
    },
    // 修改备注
    changeRemark(row) {
      this.changeRemarkdialog.dialogRow = row;
      this.changeRemarkdialog.show = true;
    },
    hideChangeRemarkdialog() {
      this.changeRemarkdialog.show = false;
    },
    passSuccess(row) {
      var text = "";
      const para = Object.assign({}, { apply_id: row.id });
      passRemark(para).then((res) => {
        this.$message.success("通过成功");
        setTimeout(() => {
          this.reload();
        }, 20);
      });
    },
    //一键通过
    passThrough() {
      let len = this.multipleSelection.length;
      if (len === 0) {
        this.$message({
          type: "warning",
          message: "请至少选择一项！",
        });
      } else {
        this.$confirm(`确定一键审核选中的 ${len} 条数据吗？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          var roIdArr = [];
          this.multipleSelection.forEach((item) => {
            roIdArr.push(item.id);
          });
          let roIdStr = roIdArr.join(",");
          onePassRemark({ apply_ids: roIdStr }).then((res) => {
            let result = res.code;
            if (result == 200) {
              this.$message({
                type: "success",
                message: "操作成功",
              });
              setTimeout(() => {
                this.reload();
              }, 20);
            } else {
              this.$message({
                type: "warning",
                message: "操作失败",
              });
            }
          });
        });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.remarkReview {
  .bottom {
    .el-button {
      padding: 0 15px;
      font-size: 13px;
    }
  }
  .el-table .cell {
    line-height: 18px;
  }
  .operateButton {
    padding: 5px 6px;
  }
}
</style>